var GLOBAL_CONFIG = GLOBAL_CONFIG || {};
GLOBAL_CONFIG['layer'] = [
    { // Scene Layer
        name: 'sceneLayer',
        resourceID: 'sceneLayer',
        items: [
            { // Scene Item
                name: 'scene',
                resourceID: 'scene',
                x: 0, y: 0,
                width: 800, height: 600,
                imageWidth: 800, imageHeight: 600,
                imageX: 100, imageY: 0
            }
        ]
    },
    { // Board Layer
        name: 'boardLayer',
        resourceID: 'boardLayer',
        items: [
            { // Board Item
                name: 'board',
                resourceID: 'board',
                x: 261, y: 38
            }
        ]
    },
    { // Tool Layer
        name: 'toolLayer',
        items: [
            { // Infomation Item
                name: 'widget.info',
                resourceID: 'widget.info',
                x: 55, y: 61,
                width: 140, height: 80,
                imageWidth: 140, imageHeight: 80,
                imageX: 0, imageY: 0
            },
            { // Menu Item
                name: 'widget.menu',
                resourceID: 'widget.menu',
                x: 55, y: 366,
                items: [
                    { // 提示按钮
                        name: 'widget.menu.hint',
                        resourceID: 'widget.menu.hint',
                        x: 79, y: 395,
                        width: 93, height: 93,
                        imageWidth: 93, imageHeight: 93,
                        imageX: 0, imageY: 0,
                        eventList: {
                            mouseMove: function () {},
                            mouseOver: function (ev) {
                                this.imageX += this.width;
                            },
                            mouseOut: function (ev) {
                                this.imageX -= this.width;
                            }
                        }
                    },
                    { // 菜单按钮
                        name: 'widget.menu.menu',
                        resourceID: 'widget.menu.menu',
                        x: 99, y: 503,
                        width: 52, height: 53,
                        imageWidth: 52, imageHeight: 53,
                        imageX: 0, imageY: 0,
                        eventList: {
                            click: function (ev) {alert('你点击了菜单！')},
                            mouseOver: function (ev) {
                                this.imageX += this.width;
                            },
                            mouseOut: function (ev) {
                                this.imageX -= this.width;
                            }
                        }
                    }
                ]
            }
        ]
    },
    { // Gem Layer
        name: 'gemLayer',
        items: (function () { // 返回 8 X 8 阵列随机宝石
            var tempItems = [];
            for (var r = 0; r < 8; r++) {
                tempItems[r] = [];
                for (var c = 0; c < 8; c++) {
                    var t = XM.lang.clone(GemUnit);
                    t.resourceID = t.randomColor(),
                    t.name = t.generateName(r, c),
                    t.row = r, t.column = c,
                    t.imageRow = 0, t.imageColumn = 0,
                    t.isImageLast = false,
                    t.isDragging = false,
                    t.isMoving = false,
                    t.isStop = true,
                    t.isHide = false,
                    t.x = t.boardPos.x + c * t.width,
                    t.y = t.boardPos.y + r * t.width,
                    t.eventList = {
                        click: function (ev) {
                            var isThisStop = false;
                            // 如果当前目标的上下左右宝石是正在转动的宝石则进行交换
                            if (GemUnit.playingGem && GemUnit.playingGem !== this) {
                                var nPlayingGem = this.isNearPlaying(tempItems);
                                if (nPlayingGem) {
                                    nPlayingGem.moveToGem(this);
                                    isThisStop = true;
                                }
                            }

                            // 宝石转动逻辑
                            if (this.isPlaying) {
                                this.isPlaying = false;
                            } else if (this.isStop) {
                                this.play();
                                if (isThisStop) this.isPlaying = false;
                            }
                        },
                        move: function (other) {
                            // 相同的颜色就不用判断了
                            //var isTBoom = this.boom(), isOBoom = other.boom();
                            if (this.resourceID === other.resourceID || !GemUnit.doBoom([this, other])) {
                                this.moveBack(other);
                            };
                        },
                        drag: function (ev) {
                            var targetGem = this.getTargetGem(ev);
                            if (targetGem !== null && !this.isMoving && !targetGem.isMoving) {
                                this.moveToGem(targetGem);
                            }
                        }
                    };
                    tempItems[r][c] = t;
                }
            }
            GemUnit.allGems = tempItems;

            return tempItems;
        })()
    }
];